package blms.util;

import java.util.regex.Pattern;

import org.apache.commons.validator.GenericValidator;
import org.apache.commons.validator.routines.*;


/**
 * Utility class, handles parameter checks.
 * 
 * @author Jonhnny Weslley
 */
public class ValidatorUtil {

	private static final String INTEGER_PATTERN = "[0-9]+";

	/**
	 * Checks if a <code>String</code> is equals to <it>null</it> or <it>""</it>.
	 * 
	 * @param value 
	 * 			The object to ckeck
	 * 
	 * @return
	 * 		<it>true</it> if a <code>String</code> is equals to <it>null</it> or <it>""</it>, 
	 * 		false otherwise.
	 */
	public static boolean isBlankOrNull(final String value) {
		return GenericValidator.isBlankOrNull(value);
	}

	/**
	 * Checks if a <code>String</code> represents a non-negative integer value.
	 * 
	 * @param value 
	 * 			The object to ckeck
	 * 
	 * @return
	 * 		<it>true</it> if a <code>String</code> represents a non-negative integer value, 
	 * 		false otherwise.
	 */
	public static boolean isInteger(final String value) {
		return !isBlankOrNull(value) && value.matches(INTEGER_PATTERN);
	}
	
	public static boolean isValidEmail(String email) {
		return email.matches(".+@.+\\.[a-z]+");
	}
}
